const Koa = require('koa')
const router = require('koa-router')()
const cors = require('koa2-cors')
const bodyParser = require('koa-bodyparser')
const serve = require('koa-static')


// 获取后端版本号
router.get('/api/sys/version', function (ctx, next) {
    console.log( ctx.request.query )
    ctx.body = require('./static/api/sys/version.js')
})

// 标准登录接口 sys/login
router.post('/api/sys/login', async function (ctx, next) {
    // await delay(2000)
    console.log( ctx.request.body )
    ctx.body = require('./static/api/sys/login.js')
})


function delay(time) {
    return new Promise(function(resolve, reject) {
        setTimeout(function(){
            resolve()
        }, time)
    })
}

//# koa业务
const app = new Koa()

app.use(cors())
app.use(bodyParser())
app.use(router.routes())
app.use(router.allowedMethods())
app.use(serve(__dirname + "/static"))

app.listen(8181, () => {
    console.log('starting at port 8181')
})